import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import VueAxios from 'vue-axios'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
axios.defaults.baseURL = 'http://localhost:8705'
axios.defaults.withCredentials = true
// Add a request interceptor
axios.interceptors.request.use(function (config) {
  // Do something before request is sent
  console.log('请求已发出')
  return config
}, function (error) {
  // Do something with request error
  return Promise.reject(error)
})

// Add a response interceptor
axios.interceptors.response.use(function (response) {
  // Do something with response data
  console.log('获取数据')
  console.log(response.data)
  return response
}, function (error) {
  // Do something with response error
  if (error.response.status === 403) {
    alert('需要登录')
    router.push('/login')
  }
  return Promise.reject(error)
})

Vue.use(ElementUI)
Vue.use(VueAxios, axios)

Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
